#编写自动化脚本
#
# import time
#
#
# from selenium import webdriver
# from selenium.webdriver.chrome.service import Service
# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.wait import WebDriverWait
# from webdriver_manager.chrome import ChromeDriverManager
#
# #1.打开浏览器————驱动管理
# #ChromeIns(保存路径）
# ChromeIns = ChromeDriverManager().install()
# time.sleep(2)
# #创建驱动对象
# driver = webdriver.Chrome(service=Service(ChromeIns))#驱动路径作为Chrome的参数
# time.sleep(2)
#
# #2.输入百度网址
# driver.get("https://www.baidu.com/")
# time.sleep(2)
#
# #3.找到百度输入框，输入关键词“迪丽热巴”
# driver.find_element(By.CSS_SELECTOR,"#chat-textarea").send_keys("迪丽热巴")
# time.sleep(2)
#
# #4.点击“百度一下”按钮
# #driver.find_element(By.CSS_SELECTOR,"#su").click()
# #time.sleep(2)
#
# #5.关闭浏览器
# driver.quit()
import datetime
import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

ChromeIns = ChromeDriverManager().install()
#浏览器配置参数
options = webdriver.ChromeOptions()
#options.add_argument('--headless')
#添加页面加载策略
options.page_load_strategy = 'eager'
driver = webdriver.Chrome(service=Service(ChromeIns),options=options)
driver.get("https://www.baidu.com/")

# driver.find_element(By.CSS_SELECTOR, "#chat-textarea").send_keys("比特就业课")
# time.sleep(3)
# driver.find_element(By.CSS_SELECTOR, "#chat-textarea").clear()
# time.sleep(3)

# text = driver.find_element(By.CSS_SELECTOR, "#chat-submit-button")
# print(text)
# time.sleep(3)

# title = driver.title
# print(title)
# url = driver.current_url
# print(url)
# driver.find_element(By.CSS_SELECTOR, "#s-top-left > a:nth-child(6)").click()
# curHandle = driver.current_window_handle
# allHandles = driver.window_handles
# for handle in allHandles:
#     if handle != curHandle:
#         driver.switch_to.window(handle)
# print(driver.title)
# print(driver.current_url)
# time.sleep(2)


#屏幕截图
#driver.save_screenshot("baidu.png")
# filename = "./images/test.png"
# driver.save_screenshot(filename)

# filename = "autotest-"+datetime.datetime.now().strftime('%Y-%m-%d-%H%M%S')+'.png'
# driver.save_screenshot('./images/'+filename)

#time.sleep(1)



driver.quit()
